<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<head th:include="/base/common_css('test')">
<body >
<div th:include="/base/common_banner"></div>
<!-- Main content starts -->

<div class="content">
    <!-- Sidebar -->
    <div th:include="/base/common_menu"></div>
    <!-- Sidebar
    <div class="sidebar">
        <div class="sidebar-dropdown"><a href="#">Navigation</a></div>

    </div>-->
    <!-- Matter -->
    <div class="mainbar">
        <!-- Page heading -->
        <div th:include="/base/common_pageHeader"></div>

        <div class="matter">
            <div class="container">
                <div class="row">
                    <div class="col-md-6">

                        <div class="widget wgreen">

                            <div class="widget-head">
                                <div class="pull-left">修改用户信息</div>
                                <div class="widget-icons pull-right">
                                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a>
                                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                                </div>
                                <div class="clearfix"></div>
                            </div>

                            <div class="widget-content">
                                <div class="padd">

                                    <!-- Form starts.  -->
                                    <form id="formid" class="form-horizontal" action="#" method="post"
                                          style="align-content: center">
                                        <input type="hidden" id="userId" th:value="${users.userId}">

                                        <div class="form-group">
                                            <label for="username" class="col-lg-4 control-label">用户名</label>
                                            <input style="width:200px" type="text" name="username"
                                                   th:value="${users.username}" readonly="readonly"
                                                   class="form-control"
                                                   id="username" placeholder="用户名">
                                        </div>
                                        <div class="form-group">
                                            <label for="phone" class="col-lg-4 control-label">手机</label>
                                            <input style="width:200px" type="text"
                                                   class="form-control" th:value="${users.phone}"
                                                   id="phone" placeholder="手机">
                                        </div>
                                        <div class="form-group">
                                            <label for="nickname" class="col-lg-4 control-label">昵称</label>
                                            <input style="width:200px " type="text"
                                                   class="form-control" th:value="${users.nickname}"
                                                   id="nickname" placeholder="昵称" onclick="checkvalue(3,this);"
                                                   onkeyup="checkvalue(3,this);" title="由2-16中文,英文，数字组成"><label
                                                id="tip3"
                                                style="color:#12aeff;font-size:12px"></label>
                                        </div>
                                        <div class="form-group">
                                            <label for="qq" class="col-lg-4 control-label">QQ</label>
                                            <input style="width:200px " type="text"
                                                   class="form-control" th:value="${users.qq}"
                                                   id="qq" placeholder="QQ" onclick="checkvalue(1,this);"
                                                   onkeyup="checkvalue(1,this);" title="由5-10位数字"><label
                                                id="tip1"
                                                style="color:#12aeff;font-size:12px"></label>
                                        </div>
                                        <div class="form-group">
                                            <label for="webchat" class="col-lg-4 control-label">微信</label>
                                            <input style="width:200px " type="text"
                                                   class="form-control" th:value="${users.webchat}"
                                                   id="webchat" placeholder="微信" onclick="checkvalue(2,this);"
                                                   onkeyup="checkvalue(2,this);" title="由6-20位字母、数字、下划线或减号组成，以字母开头！">
                                            <label
                                                    id="tip2"
                                                    style="color:#12aeff;font-size:12px"
                                                    class="form-label"></label>
                                        </div>
                                        <div class="form-group">
                                            <label for="weibo" class="col-lg-4 control-label">微博</label>
                                            <input style="width:200px " type="text"
                                                   class="form-control" th:value="${users.weibo}"
                                                   id="weibo" placeholder="微博">
                                        </div>
                                    </form>
                                    <div class="modal-footer">
                                        <button type="button" id="saveUpdateUsers"
                                                class=" btn btn-success ">
                                            保存
                                        </button>
                                        <button type="button" class="btn btn-cancel " id="cancle">取消
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!-- Mainbar ends -->
<div class="clearfix"></div>

</div>
<!-- Content ends -->

<div th:include="/base/common_footer"></div>
<!-- Scroll to top -->
<span class="totop"><a href="#"><i class="icon-chevron-up"></i></a></span>
<!--js????-->
<div th:include="/base/common_js"></div>
<script type="text/javascript">

    $("#cancle").click(function () {
        location.href = "/view/user?pageNumber=1&pageSize=10";

    })


    $("#saveUpdateUsers").click(function () {

        if (/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/.test($("#phone").val())) {

            if (/^[\u4E00-\u9FA5A-Za-z0-9]{1,16}$/.test($("#nickname").val())) {
                if (/^\d{5,10}$/.test($("#qq").val())) {
                    if (/^[a-zA-Z0-9_-]{6,20}$/.test($("#webchat").val())) {
                        $.ajax({
                            type: "get",
                            url: "/view/updateUser",
                            data: {
                                userId: $('#userId').val(),
                                username: $('#username').val(),
                                phone: $('#phone').val(),
                                nickname: $('#nickname').val(),
                                qq: $('#qq').val(),
                                webchat: $('#webchat').val(),
                                weibo: $('#weibo').val(),
                            },
                            dataType: "json",
                            success: function (data) {
                                if (data.data) {
                                    window.location.href = "/view/user?pageNumber=1&pageSize=10";
                                }
                            },

                        });
                    } else {
                        alert("保存失败！！请输入格式正确的微信号");
                    }
                } else {
                    alert("保存失败！！请输入格式正确的QQ号");
                }
            } else {
                alert("保存失败！昵称由1-16中文,英文，数字组成!!");
            }

        } else {
            alert("保存失败！！请输入格式正确的手机号");


        }

    });
    function checkvalue(n, obj) {
        var oTip = document.getElementById("tip" + n);
        if (obj.value == "") {
            oTip.innerHTML = obj.title;
        }
        else {
            oTip.innerHTML = "";
        }
    }


</script>
</body>
</html>